import { stringify } from 'qs';
import request from '@/utils/request';
import { BaiduTranslateMD5 } from '@/utils/BaiduTranslateMD5';
import { BaiduTranslate } from '@/utils/constant';
// import { hexSha1 } from '@/utils/sha1';

// 个人中心-团队
export async function queryAccountCenterTeam() {
  return [
    {
      "id": "xxx1",
      "href": "",
      "logo": "https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png",
      "member": "科学搬砖组",
    },
    {
      "id": "xxx2",
      "href": "",
      "logo": "https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png",
      "member": "全组都是吴彦祖",
    },
  ];
}

// 个人中心-文章-项目应用
export async function queryFakeList(params) {
  console.log("queryFakeList - params", params);
  return [
    {
      "id": "fake-list-0",
      "owner": "付小小",
      "title": "Alipay",
      "avatar": "https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png",
      "cover": "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png",
      "status": "active",
      "percent": 61,
      "logo": "https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png",
      "href": "https://ant.design",
      "updatedAt": "2019-01-03T09:27:56.686Z",
      "createdAt": "2019-01-03T09:27:56.686Z",
      "subDescription": "那是一种内在的东西， 他们到达不了，也无法触及的",
      "description": "在中台产品的研发过程中，会出现不同的设计规范和实现方式，但其中往往存在很多类似的页面和组件，这些类似的组件会被抽离成一套标准规范。",
      "activeUser": 168489,
      "newUser": 1182,
      "star": 148,
      "like": 108,
      "message": 13,
      "content": "段落示意：蚂蚁金服设计平台 ant.design，用最小的工作量，无缝接入蚂蚁金服生态，提供跨越设计与开发的体验解决方案。",
      "members": [
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png",
          "name": "曲丽丽",
          "id": "member1"
        },
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png",
          "name": "王昭君",
          "id": "member2"
        },
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png",
          "name": "董娜娜",
          "id": "member3"
        }
      ]
    },
    {
      "id": "fake-list-1",
      "owner": "曲丽丽",
      "title": "Angular",
      "avatar": "https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png",
      "cover": "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png",
      "status": "exception",
      "percent": 52,
      "logo": "https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png",
      "href": "https://ant.design",
      "updatedAt": "2019-01-03T07:30:34.871Z",
      "createdAt": "2019-01-03T07:30:34.871Z",
      "subDescription": "希望是一个好东西，也许是最好的，好东西是不会消亡的",
      "description": "在中台产品的研发过程中，会出现不同的设计规范和实现方式，但其中往往存在很多类似的页面和组件，这些类似的组件会被抽离成一套标准规范。",
      "activeUser": 195633,
      "newUser": 1676,
      "star": 168,
      "like": 151,
      "message": 16,
      "content": "段落示意：蚂蚁金服设计平台 ant.design，用最小的工作量，无缝接入蚂蚁金服生态，提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design，用最小的工作量，无缝接入蚂蚁金服生态，提供跨越设计与开发的体验解决方案。",
      "members": [
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png",
          "name": "曲丽丽",
          "id": "member1"
        },
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png",
          "name": "王昭君",
          "id": "member2"
        },
        {
          "avatar": "https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png",
          "name": "董娜娜",
          "id": "member3"
        }
      ]
    },
  ];
}

// 模拟登录
export async function fakeAccountLogin(params) {
  console.log("fakeAccountLogin - params", params)
  return { status: "ok", type: "account", currentAuthority: "admin" };
}

// 模拟注册
export async function fakeRegister(params) {
  console.log("fakeRegister - params", params)
  return { status: 'ok', currentAuthority: 'user' };
}

// 系统消息
export async function queryNotices() {
  return [
    {
      id: '000000001',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
      title: '你收到了 14 份新周报',
      datetime: '2017-08-09',
      type: 'notification',
    },
    {
      id: '000000007',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
      title: '朱偏右 回复了你',
      description: '这种模板用于提醒谁与你发生了互动，左侧放『谁』的头像',
      datetime: '2017-08-07',
      type: 'message',
      clickClose: true,
    },
    {
      id: '000000010',
      title: '第三方紧急代码变更',
      description: '冠霖提交于 2017-01-06，需在 2017-01-07 前完成代码变更任务',
      extra: '马上到期',
      status: 'urgent',
      type: 'event',
    },
  ];
}

// 手机验证码
export async function getFakeCaptcha(mobile) {
  console.log("getFakeCaptcha - params", mobile)
  return "captcha-xxx";
}

// TODO 登录请求
export async function login({ userName, password }) {
  // return request('/v1/auth/login', { method: 'POST', body: { usercode: userName, password: hexSha1(password) } });
  // return { status: "error", type: "account", currentAuthority: null };
  console.log(`userName=${userName} | password=${password}`);
  return { status: "ok", type: "account", currentAuthority: "admin" };
}

// TODO 登出请求
export async function logout({ usercode }) {
  // return request('/v1/auth/logout', { method: 'POST', body: { usercode } });
  console.log(`usercode=${usercode}`);
  return {};
}

// TODO 查询当前用户
export async function queryCurrent() {
  // return request('/v1/auth/currentUser');
  return {
    "name": "Admin",
    "avatar": "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png",
    "userid": "00000001",
    "email": "antdesign@alipay.com",
    "signature": "海纳百川，有容乃大",
    "title": "交互专家",
    "group": "蚂蚁金服－某某某事业群－某某平台部－某某技术部－UED",
    "tags": [
      { "key": "0", "label": "很有想法的" },
      { "key": "1", "label": "专注设计" },
      { "key": "2", "label": "辣~" },
      { "key": "3", "label": "大长腿" },
      { "key": "4", "label": "川妹子" },
      { "key": "5", "label": "海纳百川" },
    ],
    "notifyCount": 3,
    "country": "China",
    "geographic": {
      "province": { "label": "浙江省", "key": "330000" },
      "city": { "label": "杭州市", "key": "330100" },
    },
    "address": "西湖区工专路 77 号",
    "phone": "0752-268888888"
  };
}

/**
 * Baidu翻译 http://api.fanyi.baidu.com/api/trans/product/apidoc#languageList
 * @param {*} from 待翻译语言类型
 * @param {*} to 目标语言类型
 * @param {*} q  待翻译内容
 */
export async function translateBaidu(from = 'auto', to, q) {
  const appid = BaiduTranslate.appid;
  const key = BaiduTranslate.key;
  const salt = (new Date).getTime();
  const sign = BaiduTranslateMD5(appid + q + salt + key);
  const param = { appid, salt, sign, from, to, q };
  return request(`/baidu/api/trans/vip/translate?${stringify(param)}`)
}
